package com.ev.mes.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.ev.mes.dao.CrewSchedulingItemDao;
import com.ev.mes.domain.CrewSchedulingItemDO;
import com.ev.mes.service.CrewSchedulingItemService;
import com.ev.mes.vo.CrewSchedulingItemPageParam;
import com.ev.framework.utils.R;
import com.ev.apis.model.DsResultResponse;
import com.google.common.collect.Maps;


@Service
public class CrewSchedulingItemServiceImpl implements CrewSchedulingItemService {
    @Autowired
    private CrewSchedulingItemDao crewSchedulingItemDao;

    @Override
    public CrewSchedulingItemDO get(Long id) {
        return crewSchedulingItemDao.get(id);
    }

    @Override
    public List<CrewSchedulingItemDO> list(Map<String, Object> map) {
        return crewSchedulingItemDao.list(map);
    }

    @Override
    public int count(Map<String, Object> map) {
        return crewSchedulingItemDao.count(map);
    }

    @Override
    public int save(CrewSchedulingItemDO crewSchedulingItem) {
        return crewSchedulingItemDao.save(crewSchedulingItem);
    }

    @Override
    public int update(CrewSchedulingItemDO crewSchedulingItem) {
        return crewSchedulingItemDao.update(crewSchedulingItem);
    }

    @Override
    public int updateAll(CrewSchedulingItemDO crewSchedulingItem) {
        return crewSchedulingItemDao.updateAll(crewSchedulingItem);
    }

    @Override
    public int remove(Long id) {
        return crewSchedulingItemDao.remove(id);
    }

    @Override
    public int batchRemove(Long[] ids) {
        return crewSchedulingItemDao.batchRemove(ids);
    }

    @Override
    public R saveAndVerify(CrewSchedulingItemDO saveParam) {
        if (saveParam.getId() != null) {
            return crewSchedulingItemDao.update(saveParam) > 0 ? R.ok() : R.error();
        }
        return crewSchedulingItemDao.save(saveParam) > 0 ? R.ok() : R.error();
    }

    @Override
    public Map<String, Object> getById(Long id) {
        CrewSchedulingItemDO crewSchedulingItem = crewSchedulingItemDao.get(id);
        Map<String, Object> result = Maps.newHashMap();
        if (crewSchedulingItem !=null){
            result.put("data",crewSchedulingItem);
            return result;
        }
        return result;
    }

    @Override
    public Map<String, Object> pageList(CrewSchedulingItemPageParam pageParam) {
        Map<String, Object> result = Maps.newHashMap();
        List<Map<String, Object>> data = crewSchedulingItemDao.pageList(pageParam);
        if (data.size() > 0) {
            int total = crewSchedulingItemDao.pageCount(pageParam);
            result.put("data", new DsResultResponse(pageParam.getPageno(), pageParam.getPagesize(), total, data));
        }
        return result;
    }

}
